
<div class="panel-heading">
	<div id="data-edit-button">
		<button type="button" class="btn btn-primary" onclick="toggleView()">Bearbeiten</button>
		<button type="button" class="btn btn-danger pull-right" onclick="submitAjax('del_category_form', onKategorieDeleted);">Entfernen</button>
		<form id="del_category_form">
			<input type="hidden" name="c" value="Category">
			<input type="hidden" name="a" value="DeleteCategory">
			<input type="hidden" name="k_id" value="<?= HTML::Write($this->Kategorie->ID); ?>">
		</form>
	</div>
</div>

<div class="panel-body">
	<!-- Anzeige der Daten -->
	<div id="data_view">
		<h3 id="view_category_name" class="panel-title"><?= HTML::Write($this->Kategorie->Name); ?></h3>
		<div class="clearfix" />
		<br/>
		<span id="view_category_beschreibung"><?= HTML::Write($this->Kategorie->Beschreibung); ?></span>
	</div>
	
	<!-- Bearbeiten der Daten -->
	<form id="data_edit" class="form-horizontal" role="form">
		<!-- Hidden Values -->
		<input type="hidden" name="c" value="Category" />
		<input type="hidden" name="a" value="SaveCategory" />
		<input type="hidden" name="k_id" value="<?= HTML::Write($this->Kategorie->ID); ?>" />
		
		<!-- Name -->
		<div class="form-group string required category-name">
			<label class="col-sm-4 string required control-label" for="edit_category_name">Name</label>
			<div class="col-sm-6 controls">
				<input class="form-control string required" id="edit_produkt_name" name="k_name" type="text" value="<?= HTML::Write($this->Kategorie->Name); ?>" required>
			</div>
		</div>
		
		<!-- Beschreibung -->
		<div class="form-group text optional category-beschreibung">
			<label class="col-sm-4 text optional control-label" for="edit_category_beschreibung">Beschreibung</label>
			<div class="col-sm-8 controls">
				<textarea class="form-control text required" id="edit_category_beschreibung" name="k_beschreibung" required><?= HTML::Write($this->Kategorie->Beschreibung); ?></textarea>
			</div>
		</div>
		
		<!-- Speichern/Abbrechen -->
		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">
				<button id="submit-edit" class="btn btn-primary" type="button" onclick="submitAjax('data_edit', onCategorySaved);">Speichern</button>
				<button id="cancel-edit" type="reset" class="btn btn-danger" onclick="toggleView()">Abbrechen</button>
			</div>
		</div>
	</form>
</div>

<script>

	$(document).ready(function () {
<?php
	if (!empty($this->Kategorie->ID) && $this->Kategorie->ID > 0)
	{
?>
		$("#data_edit").hide();
<?php
	}
	else
	{
?>
		$("#data_view").hide();
		$("#cancel-edit").hide();
		$("#data-edit-button").hide();
<?php
	}
?>
	});
	
	function onCategorySaved(viewResponse) {
		window.location = "index.php?c=Category&k_id=" + viewResponse.data['id'];
	}
	
	function onKategorieDeleted(viewResponse) {
		window.location = "index.php?c=Category";
	}
</script>

